#include "CPhysics.h"

CPhysics* CPhysics::GetInstance( void )
{
	static CPhysics psy;
	return &psy;
}
float CPhysics::IsWalkingLeft( float fVelX, float fElapsedTime )
{
	if( fVelX > 0.0f )
	{
		return 0.0f;
	}
	if( fVelX < 0.0f )
	{
		return ( fVelX*m_fDrag);
	}
}
float CPhysics::IsWalkingRight( float fVelX, float fElapsedTime )
{
	if( fVelX < 0.0f )
	{
		return 0.0f;
	}
	if( fVelX > 0.0f ) 
	{
		return ( fVelX*m_fDrag);
	}
}
float CPhysics::IsSwimming( float fVelY, float fElapsedTime )
{
	if( m_bIsSwimming )
	{
		m_fGravity = 300.001f;
	}
	if( fVelY < 0.0f )
	{
		return ( fVelY + ( fElapsedTime * m_fGravity ) ); 
	}
	else 
	{
		m_bIsSwimming = false;
		return 0.0f;
	}
}
float CPhysics::IsJumping( float fVelY, float fElapsedTime )
{

	if( fVelY < 0.0f )
	{
		return ( fVelY + ( fElapsedTime * m_fGravity ) ); 
	}
	else
	{
		m_bIsJumping = false;
		return 0.0f;
	}
}
float CPhysics::InWater( float fVelY, float fElapsedTime )
{
	if( m_bInWater )
	{
		m_fGravity = 300.001f ;
	}
	if( fVelY < 0.0f )
	{
		return ( fVelY + ( fElapsedTime * m_fGravity ) ); 
	}
	else if( fVelY > 0.0f )
	{
		return ( fVelY - ( fElapsedTime * m_fGravity ) ); 
	}
}
float CPhysics::IsFlying( float fVelY, float fElapsedTime )
{
	if( m_bIsFlying )
	{
		m_fGravity = 0.0f;
	}
		return 0.0f;
}
float CPhysics::IsFalling( float fVelY, float fElapsedTime )
{
	if( m_bInWater )
	{
		m_fGravity = 300.001f;
		if( fVelY  <= 50.001f )
			fVelY = 50.001f;
		return ( fVelY - ( fElapsedTime * m_fGravity ) ); 
	}
	else
	{
		m_fGravity = 600.001f;
		if(fVelY > 700)
			fVelY = 700;
		return ( fVelY + ( fElapsedTime * m_fGravity ) );
	}
}